<template>
  <div class="app-container" v-loading="loading">
    <el-form :inline="true" :model="queryParams">
      <div style="display: flex;flex-wrap: wrap">

        <el-col :span="4">
          <el-form-item>
            <el-input v-model="queryParams.erpReturnCode" placeholder="退货单号（销售父单号）" clearable/>
          </el-form-item>
        </el-col>
        <el-col :span="4">
          <el-form-item>
            <el-input v-model="queryParams.erpCode" placeholder="销售子单号" clearable/>
          </el-form-item>
        </el-col>
        <el-col :span="4">
          <el-form-item>
            <el-input v-model="queryParams.skuCode" placeholder="SKU编码" clearable/>
          </el-form-item>
        </el-col>
        <el-col :span="4">
          <el-form-item>
            <el-input v-model="queryParams.skuName" placeholder="商品名称" clearable/>
          </el-form-item>
        </el-col>
        <el-col :span="4">
          <el-form-item>
            <el-input v-model="queryParams.receiptByName" placeholder="操作人" clearable/>
          </el-form-item>
        </el-col>

        <el-col :span="4">
          <el-form-item>
            <el-date-picker
                style="width:100%"
                v-model="timeData"
                start-placeholder="开始时间"
                end-placeholder="结束时间"
                range-separator="-"
                type="datetimerange"
                value-format="YYYY-MM-DD HH:mm:ss"

                unlink-panels
            />
          </el-form-item>
        </el-col>
        <el-col :span="4">
          <el-form-item>
            <el-button icon="Search" type="primary" @click="getList">查询</el-button>
            <el-button icon="Refresh" @click="resetQuery">重置</el-button>
          </el-form-item>
        </el-col>
      </div>
    </el-form>

    <div>
      <el-button type="primary">导出</el-button>
    </div>
    <vxe-table
        border
        show-overflow
        style="margin-top: 10px;"
        align="center"
        :data="tableList"
        :height="tableHeight"
        :row-config="{isCurrent: true, isHover: true}"
    >
      <vxe-column type="seq" width="80" title="序号"></vxe-column>
      <vxe-column field="erpReturnCode" width="180"  title="退货单号"></vxe-column>
      <vxe-column field="outCode" width="180"  title="出库单号"></vxe-column>
      <vxe-column field="erpCode" width="180"  title="erp销售订单号"></vxe-column>
      <vxe-column field="skuCode" width="180"  title="SKU编码"></vxe-column>
      <vxe-column field="skuName" width="220"  title="商品名称"></vxe-column>
      <vxe-column field="coverUrl"  width="180" title="商品图片">
        <template #default="{row}">
          <ImagePreview v-if="row.coverUrl" :width="150" :height="50" :src="row.coverUrl" ></ImagePreview>
        </template>
      </vxe-column>
      <vxe-column field="companyName"  width="150" title="公司名称" ></vxe-column>
      <vxe-column field="warehouseName" width="150" title="仓库名称"></vxe-column>
      <vxe-column field="totalNum" width="120"  title="客户退货数量"></vxe-column>
      <vxe-column field="qcPassNum" width="120"  title="二次入库数量"></vxe-column>
      <vxe-column field="returnVendorNum" width="120"  title="退给供应商数量"></vxe-column>
      <vxe-column field="receiptByName" width="120"  title="操作人"></vxe-column>
      <vxe-column field="receiptTime" width="200"  title="操作时间"></vxe-column>
    </vxe-table>
    <pagination
        v-show="total > 0"
        :total="total"
        v-model:page="queryParams.pageNum"
        v-model:limit="queryParams.pageSize"
        @pagination="getList"
    />
  </div>

</template>

<script setup>
import {nextTick, onMounted, reactive, ref} from "vue";
import {getReturnHistoryList} from "@/api/scApi";
import ImagePreview from "@/components/ImagePreview/index.vue";

let timeData=ref([])
let loading=ref(false)
const queryParams = ref({
  pageNum: 1,
  pageSize: 10
})
let total = ref(0)

let tableHeight = ref(0);
nextTick(() => {
  tableHeight.value = window.innerHeight - 350;
})
window.onresize = () => {
  tableHeight.value = document.body.scrollHeight - 350;
}

let tableList = ref([ ])

function getList() {
  loading.value=true
  queryParams.value.receiptStartTime=timeData.value[0]
  queryParams.value.receiptEndTime=timeData.value[1]
  let params={
    pageNum:queryParams.value.pageNum,
    pageSize:queryParams.value.pageSize,
    param:queryParams.value
  }
  getReturnHistoryList(params).then(res=>{
    loading.value =false
    if(res.code===200){
      tableList.value=res.data
      total.value=res.total
    }
  }).finally(()=>{
    loading.value =false
  })
}

const resetQuery = () => {
  timeData.value=[]
  queryParams.value = {
    pageNum: 1,
    pageSize: 10,
  }
  getList();
};

onMounted(()=>{
  getList()
})

</script>

<style scoped lang="scss">
.el-form-item {
  width: 90%;
}
</style>